import 'dart:io';

import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

class GlobalConfigService extends GetxService {
  /// 发布渠道
  var channel = "".obs;

  /// 是否 ios
  var isIOS = false.obs;

  var count1 = 0.obs;

  Future<GlobalConfigService> init() async {
    channel.value = "huawei";
    isIOS.value = Platform.isIOS;
    return this;
  }

  Future<void> getCounter() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    int count = (prefs.getInt("counter") ?? 0) + 1;
    print("count 的值为: $count");
    await prefs.setInt("counter", count);
  }

  Future<void> getCount1() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    count1.value = prefs.getInt("counter") ?? 0;

    // 这个用缓存值，是想验证这个service的生命周期是不是跟随application
    // 验证结果是的，只要程序不死，这个值就一直在内存中
    // count1.value++;
  }
}
